/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pedidos.servidor.mb.model;

import br.com.pedidos.servidor.entity.Mesa;
import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Weslley
 */
public class MesaDataModel extends ListDataModel<Mesa> implements SelectableDataModel<Mesa>, Serializable {

    public MesaDataModel() {

    }

    public MesaDataModel(List<Mesa> data) {
        super(data);
    }

    @Override
    public Object getRowKey(Mesa mesa) {
        return mesa.getNumero();
    }

    @Override
    public Mesa getRowData(String rowKey) {
        List<Mesa> mesas = (List<Mesa>) getWrappedData();

        for (Mesa mesa : mesas) {
            if (mesa.getNumero() == Integer.parseInt(rowKey)) {
                return mesa;
            }
        }

        return null;
    }

}
